<?php

/**
 * Description of registo
 *
 * @author Leonardo Lino
 */
class Registo extends CI_Controller {
    
     public function __construct() {
        parent::__construct();
        require_once 'smartyLoader.php';
        $this->smarty = $smarty;
        $this->load->model('equipaModel');
    }
    
    public function index() {
        
        $this->setAssigns();
        
        $this->smarty->assign("templateActivo", "registo.tpl.html");
        $this->smarty->display('header.tpl.html');
        $this->smarty->display('main.tpl.html');
        $this->smarty->display('footer.tpl.html');
    }
    
    public function novo(){
        global $path_url;
       $resultado = $this->equipaModel->novo($_POST['equipa'], $_POST['password2'], $_POST['email'],
                  $_POST['escola'], $_POST['morada'], $_POST['localidade'], $_POST['codpostal'], $_POST['professor'],  
                  $_POST['telefone'], $_POST['elementos'], $_POST['avatar_url']   );
            $this->index();
            
            header( 'Location: '.$path_url ) ;
    }
    
     private function setAssigns(){
         if ($this->user->isAdmin()) {
            $this->smarty->assign("isAdmin", 1);
        } else {
            $this->smarty->assign("isAdmin", 0);
        }
        
        if ($this->user->isValidUser()) {
            $this->smarty->assign("isValidUser", 1);
        } else {
            $this->smarty->assign("isValidUser", 0);
        }
        
       
        $utilizador = $this->session->all_userdata();
        if (isset($utilizador['utilizador'])){
            $user = $utilizador['utilizador'];
        } else {
            $user ='';
        }
        $this->smarty->assign("nomeAdmin", $user);
    }
}

?>